# Author    :Dun_Hz
# Time      :2025-04-07 15:57
class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n+1))
    def find(self, x):
        if x!=self.parent[x]:
            self.parent[x]=self.find(self.parent[x]) #路径压缩
        return self.parent[x]

n=int(input())
matrix=[]
for _ in range(n):
    row = list(map(int, input().split()))
    matrix.append(row)

uf=UnionFind(n)
ans=[0]*(n+1)
for i in range(1,n+1):
    for j in range(1, n+1):
        if matrix[i-1][j-1]!=0:
            p_x=uf.find(i)
            p_y=uf.find(j)
            if p_y!=p_x:
                uf.parent[p_x]=p_y
for i in range(1,n+1):
    for j in range(1, n+1):
        if matrix[i-1][j-1]!=0 and uf.find(i)==uf.find(j):
            ans[uf.find(i)]+=matrix[i-1][j-1]
            matrix[i-1][j-1]=0
            matrix[j-1][i-1]=0
sorted_ans=sorted(ans[1:], reverse=True)
for score in sorted_ans:
    if score<=0:
        break
    print(score, end=' ')

# input:
# 5
# 0 0 50 0 0
# 0 0 0 25 0
# 50 0 0 0 15
# 0 25 0 0 0
# 0 0 15 0 0
# output:
# 65 25
